Skip to content

refactor(operator-trend): collapse _side_from_status clone family (T3-2 phase 2)#75

Closed
saagpatel wants to merge 2 commits into
refactor/operator-trend-collapsefrom
refactor/operator-trend-side-collapse
Closed

refactor(operator-trend): collapse _side_from_status clone family (T3-2 phase 2)#75
saagpatel wants to merge 2 commits into
refactor/operator-trend-collapsefrom
refactor/operator-trend-side-collapse

Conversation

@saagpatel

Copy link
Copy Markdown
Owner

What

Second phased slice of the operator_resolution_trend restore-tier fractal collapse. Stacked on #74 (base = refactor/operator-trend-collapse).

Seventeen _side_from_status classifiers in the reset/reentry/rebuild/restore families each hand-spelled a confirmation-member set and its clearance mirror — the same strings with the side word swapped — cloning identical control flow seventeen ways. Replaced with a shared _resolve_side(status, *confirmation_members) helper that derives the clearance mirror once (cached via lru_cache, matching the original compiler-folded constant-set perf). Each classifier is now a one-line delegator.

Why

Pure structural duplication: 17 functions, one logic shape, mirror sets typed out by hand (a typo in any clearance string was a silent side-misclassification waiting to happen). One helper + the confirmation members as data removes the entire clone class.

How (and the safety in it)

The rewrite was a mechanical AST transform that read each confirmation set straight from source (no hardcoding) and asserted behavioral equivalence before writing — specifically that (clearance - confirmation) == (mirror(confirmation) - confirmation), which holds even for the one set that includes a confirmation-only token (just-rererestored). The transform script was run once and removed; it is not part of the diff.

Proof

  • Restore-tier golden contract: 31 passed, byte-identical (the collapsed classifiers are among the pinned 30).
  • Full suite: 2,493 passed, 2 skipped.
  • ruff check: clean (incl. import ordering for the new functools import).
  • Diff is the logical change only: +79 / −139 (net −60), no auto-formatter reflow.

Scope / follow-ups (not in this PR)

  • The 2 cross-module side classifiers (closure_forecast_reset_side_from_status, closure_forecast_reacquisition_side_from_status) match the same shape but are lone instances in their own modules; sharing _resolve_side across module boundaries is a Phase 3 cleanup, marginal gain.
  • Phase 3: dict-helper composers + deletion of the per-depth clone modules and their mirror tests.

…olve_side

Seventeen reset/reentry/rebuild/restore side classifiers each hand-spelled a
confirmation member set plus its clearance mirror (the same strings with the side
word swapped), cloning identical control flow seventeen ways. Replace them with a
shared _resolve_side(status, *confirmation_members) helper that derives the
clearance mirror once (cached); each classifier is now a one-line delegator.
Proven byte-identical by the restore-tier golden contract + full suite. Second
scalar-primitive slice of the operator_resolution_trend fractal collapse.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant